`
To see the list of environment variables set by bash, run the env
command directly from the shell:
$ env
SHELL=/bin/bash
LANGUAGE=en_CA:en
DESKTOP_SESSION=ubuntu
PWD=/home/user
--snip—
You can read individual environment variables using the echo
command. For example, to print the default shell set for the user, use
the SHELL environment variable preceded by a dollar sign ($) and
surrounded by curly braces ({}). This will cause bash to expand the
variable to its assigned value, as shown in Listing 1-1.
$ echo ${SHELL}
/bin/bash
Listing 1-1
Printing an environment variable to the terminal
Table 1-2 shows a short list of some of the default environment
variables available.
Table 1-2
Bash Environment Variables
Variable name
What It Returns
BASH_VERSION
The bash version running
BASHPID
The process ID of the current bash process
GROUPS
A list of groups the running user is a member of
HOSTNAME
The name of the host
OSTYPE
The type of operating system
PWD
The current working directory
RANDOM
A random number between 0 and 32,767
UID
The user ID of the current user
SHELL
The full pathname to the shell
Try checking the values of these environment variables:
$ echo ${RANDOM}
8744
$ echo ${UID}
1000
$ echo ${OSTYPE}
linux-gnu
Black Hat Bash (Early Access) © 2023 by Dolev Farhi and Nick Aleks